package executables;

import java.awt.Choice;
import java.awt.Component;
import java.awt.Container;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import data_structs.Hit;
import data_structs.SequenceWrapper;
import errors.IncorrectNucleotide;


public class CodeTester {
	
	static int kmer;
	static String file;
	
	class MyFrame extends JFrame implements ActionListener {

        //Create a frame with a button.
        public MyFrame() {
            super("A window");
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);

            //This button lets you close even an undecorated window.
            JButton button = new JButton("Close window");
            button.addActionListener(this);
            
            Label fileprompt = new Label("Results Filename:");
    		TextField filename = new TextField("Default");
    		Label kmerprompt = new Label("K-MER Length:");
    		Choice kmerChoice = new Choice();
    		
    		 //Place the button near the bottom of the window.
            Container contentPane = getContentPane();
            contentPane.setLayout(new BoxLayout(contentPane,
                                                BoxLayout.PAGE_AXIS));
            contentPane.add(Box.createVerticalGlue()); //takes all extra space
            contentPane.add(button);
            button.setAlignmentX(Component.CENTER_ALIGNMENT); //horizontally centered
            contentPane.add(Box.createVerticalStrut(5)); //spacer
        }

        //Make the button do the same thing as the default close operation
        //(DISPOSE_ON_CLOSE).
        public void actionPerformed(ActionEvent e) {
        	setVisible(false);
            dispose();
        }
    }

	
	public static void main(String[] args) {
		
//		String projName;
//		for(;;) {
//			for(;;) {
//				projName = (String)JOptionPane.showInputDialog(null,"Please name your folder (it must be unique)","Directory Name",
//						JOptionPane.QUESTION_MESSAGE,null,null,null);
//				if(projName != null) break;
//			}
//			
//			File f = new File("results/"+projName);
//			if( f.mkdir()) break;
//			JOptionPane.showMessageDialog(null, "Sorry, that folder already exists. Enter a different name.", "Directory Name Error",
//					JOptionPane.ERROR_MESSAGE);
//		}
//		System.out.println(projName);
		
		
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("HH.mm.ss.yyy");
		System.out.println(sdf.format(cal.getTime()));
		
		int pos = 30;
		String spos = Integer.toBinaryString(pos);
		int id = 4960540;
		String sid = Integer.toBinaryString(id);
		int info = pos << 23;
		info += id;
		
		String sinfo = Integer.toBinaryString(info);
		
		pos = info >>> 23;
		System.out.println(Integer.toBinaryString(info<<9));
		System.out.println(Integer.toBinaryString((info<<9)>>9));
		id = (info << 9) >>> 9;
		
		
		System.out.println(Integer.parseInt("1", 2));
		
		int i = -1;
		String s = Integer.toBinaryString(i);
		System.out.println(s);
		System.out.println(Integer.toString(i, 2));
		
		s = "11111111111111111111111111111111";
//		String a = "";
//		for( int j = 0; j < s.length(); j++ )
//			a += (s.charAt(j) == '0') ? "1" : "0";
//		System.out.println("-"+(Integer.parseInt(a, 2)+1));
		System.out.println(Long.parseLong(s, 2));
		long l = Long.parseLong(s, 2);
		System.out.println(l);
		
		System.out.println(Integer.parseInt("-00101111101011100100101011101010", 2));
		
		System.out.println(s=Integer.toString(-799951594,2));
		System.out.println(s);
		
		System.out.println(Integer.parseInt("10100000101000110110101", 2));
		System.out.println(Integer.parseInt("00010101", 2));
		
		try {
			SequenceWrapper sw = new SequenceWrapper("4960540","AAAAA",21,true);
			System.out.println("id:"+sw.getID()+" position:"+sw.getPosition()+" complement:"+sw.isComplement());
		} catch (IncorrectNucleotide e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("NEW "+ Integer.toString(255, 2)+" -01010101="+Byte.parseByte("-01010101", 2));
		System.out.println(Integer.toString(-85,2));
		
		Hit h = new Hit(5432465,255,42);
//		System.out.println(h.getInfo());
		System.out.println("id:"+h.getID()+" query:"+h.getQuery()+" offset:"+h.getOffset()+" shift:"+h.getShift());

		
		
		
//		setNimbusLookAndFeel();
		
//		JFrame frame = new JFrame("Information");
//		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		Prompt newContentPane = new Prompt("Default");
//		frame.setContentPane(newContentPane);
//		
//		frame.setSize(200, 200);
//		frame.setLocationRelativeTo(null);
//		frame.setVisible(true);
//		
//		String file = "";
//		int kmer = 0;
//		
//        
//		
//		for(;;) {
//			
//			file = newContentPane.finalfn;
//			kmer = newContentPane.finalkmer;
//			if( !file.equals("") && kmer != 0 ) {
//				System.out.println("yes");
//				frame.setVisible(false);
//				frame.dispose();
//				break;
//			}
//		}
//		
		
		
		
//		Label fileprompt = new Label("Results Filename:");
//		TextField filename = new TextField("Default");
//		Label kmerprompt = new Label("K-MER Length:");
//		Choice kmerChoice = new Choice();
//		for( int i = 10; i <= 30; i++ )
//			kmerChoice.add(Integer.toString(i));
//		Button submit = new Button("Submit");
//		submit.addActionListener(new ActionListener(){
//			public void actionPerformed(ActionEvent event) {
//				kmer = Integer.parseInt(kmerChoice.getSelectedItem());
//				file = filename.getText();
//				frame.setVisible(false);
//				
//			}
//			
//		});
//		
//		frame.setLayout(new GridLayout(3,2));
//		frame.add(fileprompt);
//		frame.add(filename);
//		frame.add(kmerprompt);
//		frame.add(kmerChoice);
//		frame.add(submit);
//		frame.setSize(300,100);
//		frame.setVisible(true);
		
		
//		Gui gui = new Gui();
//		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		gui.setSize(400, 400);
//		gui.setVisible(true);
	}
	public static void setNimbusLookAndFeel() {
		try {
			LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
			for( LookAndFeelInfo laf: lafs )
				if( "Nimbus".equals(laf.getName()) )
					UIManager.setLookAndFeel(laf.getClassName());
		} catch(Exception e) {
			System.out.println("Error setting Nimbus LAF: " + e);
		}
	}

}
